﻿
@{
    ViewBag.Title = "集采任务维护";
    List<NCP.Model.GroupPurchase> list = ViewData["gplist"] as List<NCP.Model.GroupPurchase>;
}

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">批次筛选</label>
                    <div class="layui-input-inline" style="width:100px">
                        @*@Html.RelGroupPurchaseSelect("GroupPurchase", "")*@

                        <select id="setpc" name="setpc" lay-filter="setpc" lay-verify="required" lay-search>
                            <option value="0">全部</option>
                            <option value="1">正在执行</option>
                            <option value="2">已到期</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">集采批次</label>
                    <div class="layui-input-inline" style="width:250px">
                        @* @Html.RelGroupPurchaseSelect("GpCode", "")*@
                        <select name="GroupPurchase" id="GroupPurchase" lay-filter="GroupPurchase" lay-verify="required">
                            <option value="">请选择集采批次</option>
                            @foreach (var item in list)
                            {
                                <option value=@item.Code>@item.Year @item.Name</option>
                            }
                        </select>
                    </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">药品</label>
                            <div class="layui-input-inline" style="width:200px">
                                <select name="drugCode" id="drugCode" lay-search>
                                    <option value="">请选择药品</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-mission-search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <div class="layui-btn-container">
                        <a id="imp" class="layui-btn layui-btn-sm">导入</a>
                        <a class="layui-btn layui-btn-sm" href="/Tmp/集采任务维护.xls">模板下载</a>
                        <a id="exp" class="layui-btn layui-btn-sm">导出</a>
                    </div>
                    <table id="LAY-mission-list" lay-filter="LAY-mission-list"></table>
                    <script type="text/html" id="barBtn">
                        <button class="layui-btn layui-btn-sm" lay-event="mission">维护</button>
                    </script>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            var admin;
            layui.config({
                base: '/layuiadmin/' //静态资源所在路径
            }).extend({
                index: 'lib/index' //主入口模块
                }).use(['index', 'table', 'admin', 'form','upload'], function () {
                var table = layui.table
                    , form = layui.form
                    , upload = layui.upload
                    , $ = layui.$;
                admin = layui.admin;
                //监听集采批次下拉框
                    form.on('select(GroupPurchase)', function (data) {
                    var type = data.value;
                    $.ajax({
                        type: 'post',
                        url: '/GroupChoseDrugCompare/GetChoseDrugInfo',
                        data: "gpcode=" + type,
                        success(res) {
                            var str = '<option value="">请选择药品</option>';
                            for (var i in res) {
                                str += "<option value='" + res[i].DrugCode + "'>" + res[i].DrugName + "</option>";
                            }
                            $('#drugCode').html(str)
                            form.render();
                        }
                    })
                    });
                    //监听批次筛选下拉框
                    form.on('select(setpc)', function (data) {
                        var type = data.value;
                        aa = type;
                        //console.log(type);
                        $.ajax({
                            type: 'post',
                            url: '/GroupChoseDrugCompare/GetGroupInfo',
                            data: "param=" + type,
                            //dataType: 'json',
                            success(res) {
                                var str = '<option value="">请选择集采批次</option>';
                                for (var i in res) {
                                    str += "<option value='" + res[i].Code + "'>" + res[i].Year + " " + res[i].Name + "</option>";
                                }
                                $('#GroupPurchase').html(str)
                                form.render();
                            }
                        })
                        //console.log(data)
                    });
                //数据绑定
                    table.render({
                        elem: '#LAY-mission-list'
                        , url: '/GroupMission/GetGpList' //模拟接口
                        //, toolbar: '#table-toolbar' //开启头部工具栏，并为其绑定左侧模板
                        , method: 'post'
                        , height:500
                        , cols: [[
                            //{ type: 'checkbox', fixed: 'left' }
                            { field: 'GpName', title: '集采名称', width: 200 }
                            , { field: 'DrugName', title: '药品名称', width: 200, sort: true }
                            , { field: 'Specs', title: '药品规格', width: 200 }
                            , { field: 'ProducerName', title: '生产企业', width: 400 }
                            , { field: 'TaskQTY', title: '医保局任务量', width: 300, sort: true}
                            , { field: 'right', title: '操作', width: 120, align: 'center', fixed: 'right', toolbar: '#barBtn' }
                        ]]
                        , page: true
                        , limit: 10
                        , limits: [10, 15, 20, 25, 30]
                        , text: { none: '暂无数据' }
                    });

                    upload.render({
                        elem: '#imp' //绑定元素
                        , url: '/GroupMission/Upload' //上传接口
                        , accept: 'file'
                        , exts: 'xls|xlsx' //只允许上传表格文件
                        , done: function (res) {
                            if (res != "-1") {
                                layer.alert("导入成功！");
                            } else {
                                layer.alert("上传失败");
                            }
                        }
                        , error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest.status + ' ' + textStatus + ' (' + errorThrown + ')');
                        }
                    });
                    $("#exp").click(function () {
                        var form = document.createElement('form');
                        form.action = '/GroupMission/Export';
                        form.method = 'post';
                        var opt = document.createElement('input');
                        opt.name = 'GroupPurchase';
                        opt.value = $("#GroupPurchase").val();
                        opt.type = 'hidden';
                        form.appendChild(opt);
                        opt = document.createElement('input');
                        opt.name = 'drugCode';
                        opt.value = $("#drugCode").val();
                        opt.type = 'hidden';
                        form.appendChild(opt);
                        $(document.body).append(form);
                        form.submit();
                    });
                //监听行工具事件
                table.on('tool(LAY-mission-list)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'mission') {
                        layer.open({
                            type: 2
                            , title: '集采任务维护'
                            , content: '/GroupMission/MissionView?GpCode=' + data.GpCode + "&DrugCode=" + data.DrugCode
                            , area: ["1000px", "600px"]
                            , maxmin: true
                        });
                    }
                    });

                //监听搜索
                form.on('submit(LAY-mission-search)', function (data) {
                    var field = data.field;
                    //执行重载
                    table.reload('LAY-mission-list', {
                        where: field,
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                });
            });
        </script>
